﻿Public Class ViewModelParametrerGroupe
    Inherits ViewModelTabSectionBase

    Dim _Reass As DataView
    Dim _TxComFrais As DataView
    Dim _Deroule As DataView
    Dim _NvleGen As DataView
    Dim _groupe As String = ""
    Dim _garantie As String = ""

    Public ReadOnly Property Reass As DataView
        Get
            If _Reass Is Nothing Then
                Dim manager As New DataManager()

                _Reass = New DataView(manager.Dataset.Reassurance)
            End If
            Return _Reass
        End Get
    End Property

    Public ReadOnly Property TxComFrais As DataView
        Get
            If _TxComFrais Is Nothing Then
                Dim manager As New DataManager()

                _TxComFrais = New DataView(manager.Dataset.CommissionsFrais)
            End If
            Return _TxComFrais
        End Get
    End Property

    Public ReadOnly Property Deroule As DataView
        Get
            If _Deroule Is Nothing Then
                Dim manager As New DataManager()

                _Deroule = New DataView(manager.Dataset.Deroule)
            End If
            Return _Deroule
        End Get
    End Property

    Public ReadOnly Property NvleGen As DataView
        Get
            If _NvleGen Is Nothing Then
                Dim manager As New DataManager()

                _NvleGen = New DataView(manager.Dataset.NouvelleGeneration)
            End If
            Return _NvleGen
        End Get
    End Property

    Public ReadOnly Property Groupes As List(Of String)
        Get
            Dim manager As New DataManager()

            Dim q1 = From r In manager.Dataset.CorrespondanceCrtPmt Select r.Groupe Distinct
            Dim q2 = From r In manager.Dataset.NouveauGroupe Select r.Groupe Distinct
            Dim q3 = From s In q1.Union(q2) Where Not String.IsNullOrEmpty(s) Select s Distinct

            Return q3.ToList()
        End Get
    End Property

    Public ReadOnly Property Garanties As List(Of String)
        Get
            Return New List(Of String)(New String() {"DC", "IT", "PE"})
        End Get
    End Property

    Public Property Groupe As String
        Get
            Return _groupe
        End Get
        Set(value As String)
            _groupe = value
            UpdateFilter()
        End Set
    End Property

    Public Property Garantie As String
        Get
            Return _garantie
        End Get
        Set(value As String)
            _garantie = value
            UpdateFilter()
        End Set
    End Property

    Private Sub UpdateFilter()
        Dim filter = "(GROUPE = '" & Groupe & "') AND (CODE_GARANTIE = '" & Garantie & "')"

        Try
            _Deroule.RowFilter = filter
            _NvleGen.RowFilter = filter
            _Reass.RowFilter = filter
            _TxComFrais.RowFilter = filter
        Catch ex As Exception

        End Try

    End Sub
End Class
